<?php 
if($_REQUEST['site_id'] > 0)
{ $modules  = getSiteModules($_REQUEST['site_id'], $_REQUEST['set']); }
else
{ $modules  = getSiteModules(0, $_REQUEST['set']); }
if($_REQUEST['site_id'] > 0):
?>
<div class="menu_top">
	<input type="hidden" name="action" value="editor_site">
	<input type="submit" value="Add Module" class="buttons" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/new.gif'); border:1px solid #DDDDDD;" />&nbsp;&nbsp;
	<select name="add_module" >
		<option value="0">Select a module</option>
		<?php
		$select = 'SELECT id, name_l, name_r FROM '.DB_PERFIX.'modules WHERE site_id=0 AND mod_id NOT IN(SELECT mod_id FROM '.DB_PERFIX.'modules WHERE site_id='.$_REQUEST['site_id'].');';
		$result = mysql_query($select);
		while($row = mysql_fetch_array($result))
		{
			echo '<option value="'.$row['id'].'">'.$row['name_l'].' '.$row['name_r'].'</option>';
		}
		?>
	</select>
    <select name="add_set" >
		<option value="0">Select a set</option>
		<?php
		foreach($modcomsets as $mcset)
		{
			echo '<option value="'.$mcset['id'].'">'.$mcset['title'].'</option>';
		}
		?>
	</select>
	<input type="submit" value="Save" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/save.gif'); border:1px solid #DDDDDD; height:20px;" class="buttons">
</div>
<?php else: ?>
<div class="menu_top">
	<input type="hidden" name="action" value="new_item">
	<input type="submit" value="Register new module" class="buttons" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/new.gif'); border:1px solid #DDDDDD;" />&nbsp;&nbsp;
	Name Left:&nbsp;&nbsp;<input name="name_l" type="text" value="" maxlength="99" size="12">
	Name Right:&nbsp;&nbsp;<input name="name_r" type="text" value="" maxlength="99" size="12">
	<input type="submit" value="Save" style="padding-left:20px; padding-right:10px;  background-image: url('../images/system/save.gif'); border:1px solid #DDDDDD; height:20px;" class="buttons">
</div>
<?php endif; ?>
<div class="menu_list">
<table id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
	<tr>
		<th nowrap="nowrap">#&nbsp;Mod ID&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Title Left&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Title Right&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Display Type&nbsp;&nbsp;</th>
		<?php if($_REQUEST['site_id'] > 0) : ?>
		<th nowrap="nowrap">HFB Set&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Site Theme&nbsp;&nbsp;</th>
		<?php else : ?>
		<th nowrap="nowrap">Module Set&nbsp;&nbsp;</th>
		<?php endif; ?>
		<th nowrap="nowrap">Active&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Edit&nbsp;&nbsp;&nbsp;</th>
		<th nowrap="nowrap">Delete&nbsp;&nbsp;&nbsp;</th>
	</tr>
	<?php 
	if($modules):
	foreach($modules as $module)
	{
	?>
	<tr class="items">
		<td nowrap="nowrap">
			<input type="hidden" name="mod_id[]" value="<?php echo $module['id']; ?>" />
			<input type="hidden" name="cat_id[]" value="<?php echo $module['cat_id']; ?>" />
			<input size="3" style="width:30px;" class="inp_txt" name="mod_mod_id[]" type="text" value="<?php echo $module['mod_id']; ?>" maxlength="90" />
		</td>
		<td nowrap="nowrap"><input style="width:80px;" class="inp_txt" name="mod_name_l[]" type="text" value="<?php echo $module['name_l']; ?>" maxlength="90" /></td>
		<td nowrap="nowrap"><input style="width:80px;" class="inp_txt" name="mod_name_r[]" type="text" value="<?php echo $module['name_r']; ?>" maxlength="90" /></td>
		<td nowrap="nowrap">
			<select name="mod_type[]" style="width:80px;" onChange="submit()">
				<option value="0" <?php if ($module['type'] == 0){echo 'selected="selected"'; }?> >Default</option>
				<option value="1" <?php if ($module['type'] == 1){echo 'selected="selected"'; }?> >List</option>
				<option value="2" <?php if ($module['type'] == 2){echo 'selected="selected"'; }?> >Block</option>
				<option value="3" <?php if ($module['type'] == 3){echo 'selected="selected"'; }?> >Form</option>
				<option value="4" <?php if ($module['type'] == 4){echo 'selected="selected"'; }?> >Player</option>
				<option value="5" <?php if ($module['type'] == 5){echo 'selected="selected"'; }?> >Banner</option>
			</select>
		</td>
		<?php if($_REQUEST['site_id'] > 0) : ?>
		<td nowrap="nowrap">
			<select name="mod_hfb_set[]" style="width:80px;" onChange="submit();" <?php if(!($_REQUEST['site_id'] > 0)){ echo 'disabled="true"'; } ?>>
				<option value="0">Default</option>
				<?php 
					if($_REQUEST['site_id'] > 0)
					{
						$hfbsets = getHFBSetList();
						if($hfbsets)
						{
							foreach($hfbsets as $hfbset)
							{
								if ($hfbset['id'] == $module['hfb_set'])
								{
									echo '<option value="'.$hfbset['id'].'" selected="selected">'.$hfbset['name'].'</option>';
								}
								else
								{
									echo '<option value="'.$hfbset['id'].'">'.$hfbset['name'].'</option>';
								}
							}
						}
					}
				?>
			</select>
		</td>
		<td nowrap="nowrap">
			<select name="mod_site_theme[]" style="width:80px;" onChange="submit();" <?php if(!($_REQUEST['site_id'] > 0)){ echo 'disabled="true"'; } ?>>
				<option value="0">Default</option>
				<?php 
					/*
					$hfbsets = getHFBSetList();
					if($hfbsets)
					{
						foreach($hfbsets as $hfbset)
						{
							if ($hfbset['id'] == $module['hfb_set'])
							{
								echo '<option value="'.$hfbset['id'].'" selected="selected">'.$hfbset['name'].'</option>';
							}
							else
							{
								echo '<option value="'.$hfbset['id'].'">'.$hfbset['name'].'</option>';
							}
						}
					}
					*/
				?>
			</select>
			<input type="hidden" name="mod_set_id[]" value="<?php echo $module['set_id']; ?>" />
		</td>
		<?php else : ?>
		<td nowrap="nowrap">
			<input type="hidden" name="mod_hfb_set[]" value="0" />
			<input type="hidden" name="mod_site_theme[]" value="0" />
			<select name="mod_set_id[]" style="width:160px;" onChange="submit();">
				<?php 
					if($modcomsets)
					{
						foreach($modcomsets as $mcset)
						{
							if ($mcset['id'] == $module['set_id'])
							{ echo '<option value="'.$mcset['id'].'" selected="selected">'.$mcset['title'].'</option>'; }
							else
							{ echo '<option value="'.$mcset['id'].'">'.$mcset['title'].'</option>'; }
						}
					}
				?>
			</select>
		</td>
		<?php endif; ?>
		<td nowrap="nowrap"><?php echo getActivationFields($module); ?></td>
		<td nowrap="nowrap">
			<a href="?con=<?php echo $_REQUEST['con']; ?>&item=<?php echo $module['id']; ?>"><img src="../images/system/templ.gif" border="0" /></a>&nbsp;
		</td>
		<td nowrap="nowrap"><input class="inp_image" type="image" name="delete_module" src="../images/system/trash_25.gif" value="0" onclick="this.value='<?php echo $module['id']; ?>'; edit_form.submit();" /></td>
	</tr>
	<?php
	}
	?>
</table>
<input type="hidden" id="activate" name="activate" value="0" />
<input type="hidden" id="deactivate" name="deactivate" value="0" />
</div>
<?php endif; ?>